#ifndef ____MUTEX_HPP____
#define ____MUTEX_HPP____

#include <pthread.h>

class Mutex
{
public:
    Mutex()
    {
        pthread_mutex_init(&_mutex,nullptr);
    }

    ~Mutex()
    {
        pthread_mutex_destroy(&_mutex);
    }

    void Lock()
    {
        pthread_mutex_lock(&_mutex);
    }

    void unLock()
    {
        pthread_mutex_unlock(&_mutex);
    }


private:
    pthread_mutex_t _mutex;
};




class AutoMutex
{
public:
    AutoMutex(Mutex& mutex)
        :_mutex(mutex)
    {
        _mutex.Lock();
    }

    ~AutoMutex()
    {
        _mutex.unLock();
    }

private:
    Mutex& _mutex;
};




#endif